package com.edu.controller.front;

import com.R;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.edu.entity.Course;
import com.edu.entity.Teacher;
import com.edu.service.CourseService;
import com.edu.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/eduservice/indexfront")
@CrossOrigin
public class IndexFrontController {

	@Autowired
	private CourseService courseService;

	@Autowired
	private TeacherService teacherService;

	@GetMapping("/index")
	public R index(){
		QueryWrapper<Course> wrapper1 = new QueryWrapper<>();
		wrapper1.orderByDesc("id");
		wrapper1.last("limit 8");
		List<Course> courseList = courseService.list(wrapper1);


		QueryWrapper<Teacher> wrapper2 = new QueryWrapper<>();
		wrapper2.orderByDesc("id");
		wrapper2.last("limit 4");
		List<Teacher> teacherList = teacherService.list(wrapper2);

		return R.ok().data("courseList",courseList).data("teacherList",teacherList);

	}
}
